package com.facebook.drawee.drawable;

import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;

public final class MatrixDrawable extends ForwardingDrawable {
    private int mUnderlyingWidth;
    private int mUnderlyingHeight;

    public MatrixDrawable(Drawable drawable) {
        super(drawable);
    }

    public final void getTransform(Matrix matrix) {
        super.getTransform(matrix);
    }

    private void configureBounds() {
        Drawable drawable = this.getCurrent();
        Rect bounds = this.getBounds();
        int underlyingWidth = drawable.getIntrinsicWidth();
        this.mUnderlyingWidth = underlyingWidth;
        int underlyingHeight = drawable.getIntrinsicHeight();
        this.mUnderlyingHeight = underlyingHeight;
        if (underlyingWidth <= 0 || underlyingHeight <= 0) {
            drawable.setBounds(bounds);
        } else {
            drawable.setBounds(0, 0, underlyingWidth, underlyingHeight);
        }
    }

    public final void draw(Canvas canvas) {
        if (this.mUnderlyingWidth != this.getCurrent().getIntrinsicWidth() || this.mUnderlyingHeight != this.getCurrent().getIntrinsicHeight()) {
            this.configureBounds();
        }
        super.draw(canvas);
    }

    protected final void onBoundsChange(Rect bounds) {
        super.onBoundsChange(bounds);
        this.configureBounds();
    }
}

